//
//  JsonExtend.swift
//  xz-app
//
//  Created by chen on 2025/5/11.
//
import SwiftUI

@propertyWrapper
struct SafeArray<T: Codable>: Codable {
    
    var wrappedValue: [T]
    
    init(wrappedValue: [T]) {
        self.wrappedValue = wrappedValue
    }
    
    init(from decoder: Decoder) throws {
        let container = try decoder.singleValueContainer()
        self.wrappedValue = (try? container.decode([T].self)) ?? []
    }
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(wrappedValue)
    }
}
